<?php
	include("includes/connect.php");
	include("includes/function.php");

	$task= $_POST["task"];
	$payfor = $_POST["payfor"];
	$inpAmount = $_POST["inpAmount"];
	$id= $_POST["id"];
	$xxx_id = $_POST["xxx_id"];

	$tablename = "temp_creditor";

	$db = new myDBS;

	switch ($task) {
		case "insert":
			if($payfor=="เลือก...") {
				die();
			}

			$sql="INSERT INTO temp_creditor (xxx_id, creditor_name, amount) values('$xxx_id', '$payfor', '$inpAmount')";
			$db->insData($sql);

			break;
		case "edit":
			//echo "i is bar";
			break;
		case "delete":
			
			$db->delData_byID($tablename, $id);
			break;
	}	
	
	$where = "xxx_id = '$xxx_id' and creditor_name IS NOT NULL";
	$result = $db->showData1($tablename, $where);

?>

<table class="table table-bordered" width="100%">
	<thead>
		<tr bgcolor="#e5e5e5">
		<th>ชื่อ - นามสกุล / บริษัท</th>
		<th>จำนวนเงิน</th>
		<th>ลบ</th>
		</tr>
	</thead>
	<tbody>
		<?php
			while ( $rows = $db->fetch_object ( $result )){
		?>
		<tr>
			<td><?php echo $rows->creditor_name; ?></td>
			<td><?php echo $rows->amount; ?></td>
			<td><a href="javascript:del_temp('<?php echo $rows->id; ?>')"><i class="icon-minus-sign"></i></a></td>
		</tr>
		<?php
			}
		?>

	</tbody>
</table>